//Erstellt von Moritz Liepe
package main;

import java.util.UUID;

import org.eclipse.draw2d.CheckBox;
import org.eclipse.draw2d.Figure;
import org.eclipse.draw2d.XYLayout;
import org.eclipse.draw2d.geometry.Rectangle;

public class CheckBoxControl extends Figure implements IModuleControl {

	private int x, y, width, height;
	private String type, address;
	private boolean connectable;
	private final XYLayout layout = new XYLayout();
	private UUID id;
	private CheckBox cb = null;
	
	public CheckBoxControl(){
		id = UUID.randomUUID();
	}
	
	public UUID getID()
	{
		return this.id;
	}
	
	public void setID(String ID){
		this.id = UUID.fromString(ID);
	}

	@Override
	public String getType() {
		return type;
	}

	@Override
	public String getAddress() {
		return address;
	}

	@Override
	public boolean isConnectable() {
		return connectable;
	}

	@Override
	public int getX() {
		return x;
	}

	@Override
	public void setX(int x) {
		this.x = x;
	}

	@Override
	public int getY() {
		return y;
	}

	@Override
	public void setY(int y) {
		this.y = y;
	}

	@Override
	public int getWidth() {
		return width;
	}

	@Override
	public void setWidth(int width) {
		this.width = width;
	}

	@Override
	public int getHeight() 
	{
		return height;
	}
	
	@Override
	public void setHeight(int height) 
	{
		this.height = height;
	}

	@Override
	public void setType(String type) 
	{
		this.type = type;
	}

	@Override
	public void setAddress(String address) 
	{
		this.address = address;
	}

	@Override
	public void setConnectable(boolean connectable) 
	{
		this.connectable = connectable;
	}

	@Override
	public void paint() 
	{
		if(cb == null)
		{
			this.setLayoutManager(layout);	
			this.setOpaque(true);
				
			cb = new CheckBox();
			this.add(cb, new Rectangle(0, 0, width, height));
		}
		
		
	}

	@Override
	public String getValue() 
	{
		if(cb == null)
		{
			return new String();
		}
		return Boolean.toString(cb.isSelected());
	}

	@Override
	public void setValue(String value) 
	{
		if((cb != null) && (value != null))
		{
			if(value.equals(Boolean.toString(true)))
			{
				System.out.println("CB: " + true);
				cb.setSelected(true);
			}
			else
			{
				System.out.println("CB: " + false);
				cb.setSelected(false);
			}
			//this.cb.repaint();
			//this.repaint();
		}
		
	}

}
